package com.cn.gxa.controller;

import com.cn.gxa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {

    private final UserService userService;


    @RequestMapping(value = "/changeAuth")
    @ResponseBody//转为 json   默认为String
    public  int changeAuth(Integer  idA,Integer idB){
       return   this.userService.changeAuth(idA,idB);
    }




    @Autowired  //  @Resource
    public UserController(UserService userService) {
        System.out.println("--------------------------UserController构造函数");
        this.userService = userService;
    }

    @RequestMapping(value = "/login")
    public String selectUser(@RequestParam String username, @RequestParam String password) {
        System.out.println("UserController --------------------------selectUser");
        System.out.println("UserController ------username=" + username);
        System.out.println("UserController ------password=" + password);

        return "redirect:login.jsp";
    }


    @RequestMapping(value = "/reg")
    public String regUser(@RequestParam String username, @RequestParam String password) {
        System.out.println("UserController --------------------------regUser");
        System.out.println("UserController ------username=" + username);
        System.out.println("UserController ------password=" + password);
        userService.regUser(username, password);
        return "redirect:login.jsp";
    }


}
